package com.ruoyi.shebei.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shebei.domain.Ledger;
import com.ruoyi.shebei.service.ILedgerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备台账Controller
 * 
 * @author admin
 * @date 2024-08-02
 */
@RestController
@RequestMapping("/shebei/ledger")
public class LedgerController extends BaseController
{
    @Autowired
    private ILedgerService ledgerService;

    /**
     * 查询设备台账列表
     */
    @PreAuthorize("@ss.hasPermi('shebei:ledger:list')")
    @GetMapping("/list")
    public TableDataInfo list(Ledger ledger)
    {
        startPage();
        List<Ledger> list = ledgerService.selectLedgerList(ledger);
        return getDataTable(list);
    }

    /**
     * 导出设备台账列表
     */
    @PreAuthorize("@ss.hasPermi('shebei:ledger:export')")
    @Log(title = "设备台账", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Ledger ledger)
    {
        List<Ledger> list = ledgerService.selectLedgerList(ledger);
        ExcelUtil<Ledger> util = new ExcelUtil<Ledger>(Ledger.class);
        util.exportExcel(response, list, "设备台账数据");
    }

    /**
     * 获取设备台账详细信息
     */
    @PreAuthorize("@ss.hasPermi('shebei:ledger:query')")
    @GetMapping(value = "/{ledgerId}")
    public AjaxResult getInfo(@PathVariable("ledgerId") Long ledgerId)
    {
        return success(ledgerService.selectLedgerByLedgerId(ledgerId));
    }

    /**
     * 新增设备台账
     */
    @PreAuthorize("@ss.hasPermi('shebei:ledger:add')")
    @Log(title = "设备台账", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Ledger ledger)
    {
        return toAjax(ledgerService.insertLedger(ledger));
    }

    /**
     * 修改设备台账
     */
    @PreAuthorize("@ss.hasPermi('shebei:ledger:edit')")
    @Log(title = "设备台账", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Ledger ledger)
    {
        return toAjax(ledgerService.updateLedger(ledger));
    }

    /**
     * 删除设备台账
     */
    @PreAuthorize("@ss.hasPermi('shebei:ledger:remove')")
    @Log(title = "设备台账", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ledgerIds}")
    public AjaxResult remove(@PathVariable Long[] ledgerIds)
    {
        return toAjax(ledgerService.deleteLedgerByLedgerIds(ledgerIds));
    }
}
